package com.capinfo.accounting.web;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.capinfo.accumulation.model.accounting.mybist.ZDPZCWPZMB;
import com.capinfo.accumulation.model.pagemodel.Json;
import com.capinfo.accumulation.parameter.accounting.DataGrid;
import com.capinfo.accumulation.service.accounting.mybits.ZDPZCWPZMBServiceI;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import net.sf.json.JSONArray;

/**
 *  @author zxl
 */
@Controller
@RequestMapping("/zDPZCWPZMBController")
public class ZDPZCWPZMBController extends BaseController {
	@Autowired
	public ZDPZCWPZMBServiceI zDPZCWPZMBService;

	@RequestMapping("/dataGrid.shtml")
	@ResponseBody
	public DataGrid dataGrid(@RequestParam  Map param) {
		return zDPZCWPZMBService.findbyByGrid(param);
		
	}
	@RequestMapping("/dataGrid1.shtml")
	@ResponseBody
	public DataGrid dataGrid1(@RequestParam  Map param) {
		return zDPZCWPZMBService.findbyByGrid1(param);
		
	}
	@RequestMapping("/bj.shtml")
	@ResponseBody
	public Json bj(String jsonString,long id) throws IllegalAccessException, InvocationTargetException
	
	{		String str1=jsonString;
			String ss=null;
		try {
			 ss=new String(str1.getBytes("ISO-8859-1"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
			Json j = new Json();
			Gson gson = new Gson();  
			  List<ZDPZCWPZMB> retList = gson.fromJson(ss,  
		                new TypeToken<List<ZDPZCWPZMB>>() {  
		                }.getType());  
		        for (ZDPZCWPZMB t : retList) {  
		            if(t.getID()!=null){
			        	zDPZCWPZMBService.updateByPrimaryKeySelective(t);
		            }
			        else{
			        	t.setZDPZMBID(id);
			        	zDPZCWPZMBService.insert(t);
			        }
		        }  
			j.setSuccess(true);
			j.setMsg("保存成功");
			j.setObj("");
		return j;
	}
	
	@RequestMapping("/add.shtml")
	@ResponseBody
	public Json add(ZDPZCWPZMB t , HttpSession session) {
		Json j = new Json();
		try {
			zDPZCWPZMBService.insert(t);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
			j.setObj(t);
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/edit.shtml")
	@ResponseBody
	public Json edit(ZDPZCWPZMB t , HttpSession session) {
		Json j = new Json();
		try {
			zDPZCWPZMBService.updateByPrimaryKeySelective(t);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
			j.setObj(t);
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	
	@RequestMapping("/update.shtml")
	@ResponseBody
	public Json update(String FLXH,String id,String ZDPZMBID) {
		Json j = new Json();
		try {
			zDPZCWPZMBService.deleteByPrimaryKey(id);
			zDPZCWPZMBService.updateByFLXH(FLXH,ZDPZMBID);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
		
	}

	@RequestMapping("/delete.shtml")
	@ResponseBody
	public Json delete(String id) {
		Json j = new Json();
		try {
			zDPZCWPZMBService.deleteByPrimaryKey(id);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/selectByid.shtml")
	@ResponseBody
	public ZDPZCWPZMB selectByid(String id) {
		return zDPZCWPZMBService.selectByPrimaryKey(id);
	}
	
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/manager")
	public String manager() {
		return "/zDPZCWPZMB/zDPZCWPZMB";
	}
	
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/addPage")
	public String addPage(HttpServletRequest request) {
		ZDPZCWPZMB zDPZCWPZMB  = new ZDPZCWPZMB();
		request.setAttribute("zDPZCWPZMB", zDPZCWPZMB);
	return "/zDPZCWPZMB/zDPZCWPZMBAdd";
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/editPage")
	public String editPage(String id ,HttpServletRequest request) {
		ZDPZCWPZMB zDPZCWPZMB = this.zDPZCWPZMBService.selectByPrimaryKey(id);
		request.setAttribute("zDPZCWPZMB", zDPZCWPZMB);
		return "/zDPZCWPZMB/zDPZCWPZMBEdit";
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/viewPage")
	public String viewPage(String id ,HttpServletRequest request) {
		ZDPZCWPZMB zDPZCWPZMB = this.zDPZCWPZMBService.selectByPrimaryKey(id);
		request.setAttribute("zDPZCWPZMB", zDPZCWPZMB);
		return "/zDPZCWPZMB/zDPZCWPZMBView";
	}
}
